﻿@model CanDichVU.Models.LocalEmailModel
@{
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequestChangeEmail"
    };
}

<div class="formdangky divChangeEmail">
    @using (Ajax.BeginForm("ChangeEmail", "Account", null, ajaxOpts, new { enctype = "multipart/form-data", name = "frm_register", id = "frm_register" }))
    {
        <ul class="formreg">
            <li></li>
            <li class="warning-area-changeEmail"></li>
            <li>
                <label class="left">Mật khẩu</label>
                <span class="right">
                    @Html.PasswordFor(model => model.Password, new { name = "Pass", @placeholder = "Mật khẩu (bắt buộc từ 3 -> 9 ký tự)", value = "", style = "width: 86%;" })
                </span>
            </li>
            <li>
                <label class="left">Email cũ</label>
                <span class="right">
                    @Html.TextBoxFor(model => model.OldEmail, new {@disabled="disabled", name = "OldEmail", @placeholder = "", value = "", style = "width: 86%;" })
                    <span id="email-result-check"></span>
                </span>
            </li>
            <li class="line">
                <label class="left">Email mới</label>
                <span class="right">
                    @Html.TextBoxFor(model => model.NewEmail, new { name = "NewEmail", @placeholder = "Nhập email mới", value = "", style = "width: 86%;" })
                </span>
            </li>
            <li class="line">
                <label class="left">Nhập lại Email mới</label>
                <span class="right">
                    @Html.TextBoxFor(model => model.ConfirmEmail, new { name = "ConfirmEmail", @placeholder = "Nhập lại email mới", value = "", style = "width: 86%;" })
                </span>
            </li>
            <li class="fone_num">
                        <div class="clear"></div>
                         <div class="right">
                            @Html.Partial("_Captcha", new CanDichVU.Models.Captcha())
                            @Html.Partial("_InvisibleCaptcha", new CanDichVU.Models.InvisibleCaptcha())
                         </div>
                    </li>
            <li class="clear"></li>
            <li class="line"><span class="left">&nbsp;</span> <span class="right">
                        <input type="submit" style="border: 0;" onclick="return loadmaskloadingChangeEmail();" class="btnsubmit" value="Thay Đổi Email" name=""></span>
                    </li>
        </ul>
    }
</div>

<link href="~/Scripts/jquery-loadmask/jquery.loadmask.css" rel="stylesheet" />
<script src="~/Scripts/jquery-loadmask/jquery.loadmask.js"></script>
<script type="text/javascript">

    function loadmaskloadingChangeEmail() {
        $(".divChangePass").mask("Dữ liệu đang xử lý...", 500);
    }


    function completedAjaxRequestChangeEmail(obj) {
        var returnObj = eval('(' + obj.responseText + ')');
        if (returnObj.Status == "success") {
            $(".divChangeEmail").unmask();
            $("#Email").val(returnObj.RedirectUrl);
            $("#OldEmail").val(returnObj.RedirectUrl);
            makeSccuessHighlightChangeEmail("Thay đổi Email Thành Công");

        } else {
            makeErrorHighlightChangeEmail(returnObj.Message);
            $(".divChangeEmail").unmask();
        }
        return false;
    }

    function makeErrorHighlightChangeEmail(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='' style='float: left;'></span><strong>Lỗi: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area-changeEmail");
        $highlight.delay(4000).fadeOut(500);

    }

    function makeSccuessHighlightChangeEmail(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='' style='float: left;'></span><strong>Thành công: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area-changeEmail");
        $highlight.delay(4000).fadeOut(800);

    }

</script>
